<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Util\Tool;

class PersonalDetailsController extends BaseController
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * 医院保存
     */
    public function hospital(Request $request)
    {
        if (empty($request->hospital)) {
            return $this->ResultJson(0, "填写医院不能为空", []);
        }
        $user = Tool::ApiTokenGetDoctorUser($request->api_token);
        $user->hospital = $request->hospital;
        $user->save();
        //更新token
        Tool::SetDoctorAndUpToken($request->api_token, $user->account);
        return $this->ResultJson(1, "保存成功!", []);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * 擅长保存
     */
    public function beadeptat(Request $request)
    {
        if (empty($request->skill)) {
            return $this->ResultJson(0, "填写擅长不能为空", []);
        }
        $user = Tool::ApiTokenGetDoctorUser($request->api_token);
        $user->skill = $request->skill;
        $user->save();
        //更新token
        Tool::SetDoctorAndUpToken($request->api_token, $user->account);
        return $this->ResultJson(1, "保存成功!", []);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * 科室保存
     */
    public function clinicId(Request $request)
    {
        if (empty($request->clinicId)) {
            return $this->ResultJson(0, "填写选择科室", []);
        }
        $user = Tool::ApiTokenGetDoctorUser($request->api_token);
        $user->clinic_id = $request->clinicId;
        $user->save();
        //更新token
        Tool::SetDoctorAndUpToken($request->api_token, $user->account);
        return $this->ResultJson(1, "保存成功!", []);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * 简介保存
     */
    public function introduce(Request $request)
    {
        if (empty($request->introduce)) {
            return $this->ResultJson(0, "填写填写简介", []);
        }
        $user = Tool::ApiTokenGetDoctorUser($request->api_token);
        $user->introduce = $request->introduce;
        $user->save();
        //更新token
        Tool::SetDoctorAndUpToken($request->api_token, $user->account);
        return $this->ResultJson(1, "保存成功!", []);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * 保存职称
     */
    public function professionalId(Request $request)
    {
        if (empty($request->professional_id)) {
            return $this->ResultJson(0, "填选择职称", []);
        }
        $user = Tool::ApiTokenGetDoctorUser($request->api_token);
        $user->professional_id = $request->professional_id;
        if (!empty($request->certificate)) {
            $user->certificate = json_encode(Tool::handelString($request->certificate));
        }
        $user->save();
        //更新token
        Tool::SetDoctorAndUpToken($request->api_token, $user->account);
        return $this->ResultJson(1, "保存成功!", []);
    }
}
